use thiserror::Error;

use bc_base::{BlockId, block::BlockError};

#[derive(Error, Debug, PartialEq)]
pub enum BlockIndexError {
    #[error("Prev block index node not found for block id ({0})")]
    PrevBlockIndexNodeNotFound(BlockId),

    // already have the block
    #[error("Block index node ({0}) already exists")]
    BlockIndexNodeAlreadyExists(BlockId),

    #[error("Prev of fork is none")]
    PrevOfForkIsNone,

    #[error("Prev of longer is none")]
    PrevOfLongerIsNone,

    // BlockError
    #[error("BlockError: {0}")]
    BlockError(#[from] BlockError),

    // ConnectBlockFailed
    #[error("ConnectBlockFailed")]
    ConnectBlockFailed,

    // TopStorageError
    #[error("TopStorageError: {0}")]
    TopStorageError(#[from] bc_lib::top_storage::TopStorageError),

    // PrevTxIndexOutOfRange
    #[error("PrevTxIndexOutOfRange")]
    PrevTxIndexOutOfRange,

    // TransactionConsensusError
    #[error("TransactionConsensusError: {0}")]
    TransactionConsensusError(#[from] crate::transaction::TransactionConsensusError),

    #[error("BlockFeeIsTooLarge")]
    BlockFeeIsTooLarge,
}

mod block_index_impl;
mod data_manager;

pub(crate) use block_index_impl::BlockAndIndexManager;
